﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ERF.Menu
{
    /// <summary>
    /// This class creates a menu list and is controlling
    /// the selected item in the menu list.
    /// </summary>

    public class MenuList : MenuItem
    {
        private List<MenuItem> menuItems = new List<MenuItem>();
        private MenuItem selectedItem;
        private MenuList parentList;
        private Menu menu;

        /// <summary>
        /// Creates a MenuList
        /// </summary>
        public MenuList(String title) : base(title)
        {
            
        }

        /// <summary>
        /// Creates a MenuList with reference to it's parent list
        /// so it's possible to go back and forth between items.
        /// </summary>
        public MenuList(String title, MenuList parentList, Menu menu) : base(title)
        {
            this.parentList = parentList;
            this.menu = menu;
            this.action = SelectThisMenuList;
        }

        /// <summary>
        /// Sets or gets the Parent List of this MenuList
        /// </summary>
        public MenuList ParentList
        {
            get { return parentList; }
            set { parentList = value; }
        }

        /// <summary>
        /// Use this to add or remove menuItems in the menu.
        /// </summary>
        public List<MenuItem> MenuItems
        {
            get { return menuItems; }
            set { menuItems = value; }
        }
        /// <summary>
        /// Selects a menu item in the menu list.
        /// </summary>
        public MenuItem SelectedItem
        {
            get { return selectedItem; }
            set { selectedItem = value; }
        }

        /// <summary>
        /// private method that is called when this
        /// menu item is submitted.
        /// </summary>
        private void SelectThisMenuList()
        {
            this.menu.CurrentList = this;
        }
    }
}
